Imports System.Xml
Imports System.IO
Public Class Form3
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'ListBox1
        '
        Me.ListBox1.Location = New System.Drawing.Point(8, 40)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(168, 394)
        Me.ListBox1.TabIndex = 0
        '
        'PictureBox1
        '
        Me.PictureBox1.Location = New System.Drawing.Point(208, 40)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(168, 240)
        Me.PictureBox1.TabIndex = 1
        Me.PictureBox1.TabStop = False
        '
        'Label1
        '
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(200, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.TabIndex = 2
        Me.Label1.Text = "DVD Cover"
        '
        'Label2
        '
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.Location = New System.Drawing.Point(8, 16)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(136, 23)
        Me.Label2.TabIndex = 3
        Me.Label2.Text = "Collection Listing"
        '
        'Form3
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(528, 446)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.PictureBox1)
        Me.Controls.Add(Me.ListBox1)
        Me.Name = "Form3"
        Me.Text = "Preview"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public xmlFile As String
    Public dirProfile As String
    Public strVersion As String

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadXMLFile()
    End Sub

    Private Sub LoadXMLFile()

        Dim ds As New DataSet
        Dim dsTable As New DataTable
        Dim m_xmld As XmlDocument
        Dim m_nodelist As XmlNodeList
        Dim m_node As XmlNode
        Dim count As Integer = 0
        Dim indTitleID As Integer
        Dim indSortTitle As Integer
        Dim count2 As Integer = 0

        'Create the XML Document
        m_xmld = New XmlDocument

        'Load the Xml file
        m_xmld.Load(xmlFile)

        'Get the list of name nodes 
        m_nodelist = m_xmld.SelectNodes("/Collection/DVD")

        'For count2 = 0 To m_nodelist.Count - 1

        '    For count = 0 To m_nodelist.Item(count2).ChildNodes.Count - 1
        '        If m_nodelist.Item(0).ChildNodes.Item(count).Name = "ID" Then
        '            indTitleID = count
        '        End If
        '        If m_nodelist.Item(count2).ChildNodes.Item(count).Name = "SortTitle" Then
        '            indSortTitle = count
        '        End If
        '    Next

        '    Me.ListBox1.Items.Add(m_nodelist.Item(count2).Item(indSortTitle).InnerText)

        'Next

        'dsTable.TableName = "Titles"

        'dsTable.Columns.Add("Title")
        'dsTable.Columns.Add("ID")


        For Each m_node In m_nodelist

            For count = 0 To m_node.ChildNodes.Count - 1
                'If m_node.ChildNodes.Item(count).Name = "ID" Then
                '    indTitleID = count
                'End If
                If m_node.ChildNodes.Item(count).Name = "SortTitle" Then
                    indSortTitle = count
                End If
            Next

            Me.ListBox1.Items.Add(m_node.ChildNodes.Item(indSortTitle).InnerText)

        Next

        Me.ListBox1.Sorted = True

    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        Dim m_xmld As XmlDocument
        Dim m_nodelist As XmlNodeList
        Dim m_node As XmlNode
        Dim count As Integer = 0
        Dim indTitleID As Integer
        Dim indSortTitle As Integer


        'Create the XML Document
        m_xmld = New XmlDocument

        'Load the Xml file
        m_xmld.Load(xmlFile)

        'Get the list of name nodes 
        m_nodelist = m_xmld.SelectNodes("/Collection/DVD")

        'For count = 0 To m_nodelist.Item(0).ChildNodes.Count - 1
        '    If m_nodelist.Item(0).ChildNodes.Item(count).Name = "ID" Then
        '        indTitleID = count
        '    End If
        '    If m_nodelist.Item(0).ChildNodes.Item(count).Name = "SortTitle" Then
        '        indSortTitle = count
        '    End If
        'Next

        For Each m_node In m_nodelist

            For count = 0 To m_node.ChildNodes.Count - 1
                If m_node.ChildNodes.Item(count).Name = "ID" Then
                    indTitleID = count
                End If
                If m_node.ChildNodes.Item(count).Name = "SortTitle" Then
                    indSortTitle = count
                End If
            Next

            If m_node.ChildNodes.Item(indSortTitle).InnerText = Me.ListBox1.SelectedItem.ToString Then

                If strVersion = "2" Then
                    If File.Exists(dirProfile + "\Images\" + m_node.ChildNodes.Item(indTitleID).InnerText + "f.jpg") Then
                        Me.PictureBox1.Image = System.Drawing.Image.FromFile(dirProfile + "\Images\" + m_node.ChildNodes.Item(indTitleID).InnerText + "f.jpg")
                    Else
                        Me.PictureBox1.Image = Nothing
                        Exit Sub
                    End If
                End If

                If strVersion = "3" Then
                    If File.Exists(dirProfile + "\Databases\Default\Images\" + m_node.ChildNodes.Item(indTitleID).InnerText + "f.jpg") Then
                        Me.PictureBox1.Image = System.Drawing.Image.FromFile(dirProfile + "\Databases\Default\Images\" + m_node.ChildNodes.Item(indTitleID).InnerText + "f.jpg")
                    Else
                        Me.PictureBox1.Image = Nothing
                        Exit Sub
                    End If
                End If

                Me.PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize

                Exit Sub

            End If

        Next

    End Sub
End Class


